package com.kuang.controller;

import com.kuang.pojo.AstManageDeviceOpen;
import com.kuang.pojo.AstUserCardRecharge;
import com.kuang.service.asset.AstManageDeviceOpenService;
import com.kuang.service.asset.AstUserCardRechargeService;
import lombok.extern.log4j.Log4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/asset/")
@Log4j
public class AstManageDeviceOpenController {

    @Resource
    AstManageDeviceOpenService astManageDeviceOpenService;

    /**
     * 获取全部数据
     * @param model
     * @return
     */
    @RequestMapping("getAstManageDeviceOpens")
    public String getAstManageDeviceOpens(Model model){
        List<AstManageDeviceOpen> astManageDeviceOpens = astManageDeviceOpenService.selectAll();
        model.addAttribute("datas",astManageDeviceOpens);
        model.addAttribute("device_code","");
        model.addAttribute("ver","");
        return "mqtt/ast_manage_device_open_list";
    }

    /**
     * 获取数据通过条件
     * @param model
     * @return
     */
    @PostMapping("getAstManageDeviceOpensByExample")
    public String getAstManageDeviceOpensByExample(AstManageDeviceOpen astManageDeviceOpen,Model model){

        List<AstManageDeviceOpen> astManageDeviceOpens = astManageDeviceOpenService.selectAllByExample(astManageDeviceOpen);
        model.addAttribute("datas",astManageDeviceOpens);
        model.addAttribute("device_code",astManageDeviceOpen.getDevice_code());
        model.addAttribute("ver",astManageDeviceOpen.getVer());
        return "mqtt/ast_manage_device_open_list";
    }

    /**
     * 获取设备信息通过id
     * @param model
     * @return
     */
    @RequestMapping("getAstManageDeviceOpensById/{id}")
    public String getAstManageDeviceOpensById(@PathVariable("id") String id, Model model){
        AstManageDeviceOpen astManageDeviceOpen = new AstManageDeviceOpen();
        astManageDeviceOpen.setAst_manage_device_open_id(id);
        List<AstManageDeviceOpen> astManageDeviceOpens = astManageDeviceOpenService.selectAllByExample(astManageDeviceOpen);
        model.addAttribute("data",astManageDeviceOpens.get(0));
        return "mqtt/ast_manage_device_open_from";
    }

}
